﻿using System.Collections.Generic;
using Kaio.Core;

namespace MvcForum.Net.Bussiness
{
    public class IPLockRepo
    {
        public static List<IPLock> List()
        {

            var _data = CacheHelper.Get<List<IPLock>>(CacheKeys.IP_LOCKS);

            if (_data == null)
            {
                _data = MainDB.Instant.IPLock_List().ExecuteTypedList<IPLock>();

                if (_data.Count > 0)
                {
                    CacheHelper.Add(CacheKeys.IP_LOCKS, _data);
                }

            }

            return _data;
        }


        public static List<IPLock> All()
        {
            return MainDB.Instant.IPlock_ListAll().ExecuteTypedList<IPLock>();
        }



        public static void Save(IPLock i)
        {
            MainDB.Instant.IPLock_Save(i.Id, i.Mask, i.Reason, i.Expires).Execute();
            CacheHelper.Remove(CacheKeys.IP_LOCKS);
        }

        public static IPLock Info(int id)
        {
            var _data = MainDB.Instant.IPLock_Detail(id).ExecuteTypedList<IPLock>();

            return _data.Count > 0 ? _data[0] : null;
        }

        public static void Del(string ids)
        {
            MainDB.Instant.IPLock_Delete(ids).Execute();
            CacheHelper.Remove(CacheKeys.IP_LOCKS);
        }
    }
}